<%-- 
    Document   : DelProblem
    Created on : 24/04/2011, 08:41:22 PM
    Author     : Jhon
--%>
<%@page import="java.util.List"%>
<%@page import="vo.VOProblem"%>
<%@page import="control.Controller"%>
<%@page import="vo.VOUser"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="HTML.*"%>
<%@include file="CheckSession.jsp"%>
<% String search = request.getParameter("search");
   String busqueda = request.getParameter("busqueda");
   if(search== null || search==""){
    response.sendRedirect("./DeleteProblemas.jsp");
    return;
   }

      
   Controller con = Controller.getInstance();
   VOProblem p;
   if(busqueda.equals("1")){
    try{
     p = con.findProblem(search.trim());
    }catch(Exception e){
    response.sendRedirect("./DeleteProblemas.jsp");
    return;
    }
   if(p==null){
      response.sendRedirect("./DeleteProblemas.jsp");
      return;
    }
    try{
        con.deleteProblem(p);
    }catch(Exception e){
        session.setAttribute("ERROR", e.getMessage());
        response.sendRedirect("../Error/Error.jsp");
        return;
    }
    response.sendRedirect("./ListaProblemas.jsp");    
    return;
   }else if(busqueda.equals("2")){
    try{
     p = con.findProblem(search);
     }catch(Exception e){
    response.sendRedirect("./DeleteProblemas.jsp");
    return;
    }


    if(p==null){
      response.sendRedirect("./DeleteProblemas.jsp");
      return;
    }

    try{
        con.deleteProblem(p);
    }catch(Exception e){
        session.setAttribute("ERROR", e.getMessage());
        response.sendRedirect("../Error/Error.jsp");
        return;
    }

    response.sendRedirect("./ListaProblemas.jsp");
    return;
   }else{
       response.sendRedirect("./DeleteProblemas.jsp");
  /* c.addSearch("Buscar Problemas", "Problemas/BuscarProblema.jsp");
   String[] datos ={"id","Nombre","NS","NAS"};
   c.addInitLista("Problemas","600", datos);
  List<VOProblem> list = con.getProblemsByKeyword(search);
  datos = new String[4];
   VOProblemStats stats;
   if(list!=null && !list.isEmpty())
   for(VOProblem pr:list){
    datos[0]=String.valueOf(pr.getIdProblem());
    datos[1]=pr.getName();
    stats = con.getProblemStats(pr.getName());
    datos[2]=String.valueOf(stats.getSubmissions());
    datos[3]=String.valueOf(stats.getAccepted());
    c.addDataLista(datos);
   }
   c.addEndLista();*/

   }

    %>
